<template>
	<view class="page">
		<view class="title">
			请选择您的学校
		</view>
		<view class="tips">
			仅有一次选择机会，请正确选择您的学校
		</view>
		<view class="search">
			<u--input placeholder="请输入学校名称" border="bottom" inputAlign='center' v-model="name"
				@confirm="init"></u--input>
		</view>
		<scroll-view scroll-y="true" class="ul">
			<view class="li" v-for="(item,index) in schoolArr" :key="index" @click="goLogin(item)">
				<image :src="item.image" mode="widthFix" class="image"></image>
				<view class="name">
					{{item.name}}
				</view>
			</view>
		</scroll-view>

	</view>
</template>

<script>
	import {
		schoolList,
		memberUpdate
	} from '@/api.js'
	export default {
		data() {
			return {
				schoolArr: [],
				name: ''
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				schoolList({
					name: this.name
				}).then(res => {
					this.schoolArr = res.result
					console.log('res', res);
				})
			},
			async goLogin(item) {
				let res = await memberUpdate({
					schoolId: item.id
				})
				console.log('res', res);
				if (res.code == 200) {
					uni.showToast({
						title: "绑定成功",
						icon: "none"
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}, 2000)
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {
		background: rgba(247, 247, 247, 1);

	}

	.title {
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 43.26rpx;
		line-height: 100%;
		letter-spacing: -0.96px;
		color: #000000;
		padding: 47rpx 0 0 65rpx;

	}

	.tips {
		font-family: PingFang SC;
		font-weight: 400;
		font-size: 32rpx;
		line-height: 100%;
		letter-spacing: -0.96px;
		color: #AFB2B9;
		padding: 12rpx 0 40rpx 65rpx;
	}

	.ul {
		width: 680rpx;
		padding: 0 36rpx;

		.li {
			display: flex;
			align-items: center;
			height: 125rpx;
			border-radius: 25rpx 25rpx 25rpx 25rpx;
			background: #fff;
			margin-bottom: 12rpx;
			padding: 18rpx 40rpx;
			box-sizing: border-box;

			.image {
				width: 88rpx;
				margin-right: 16rpx;
			}

			.name {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				letter-spacing: -0.96px;
				text-align: center;
				color: #000000;

			}
		}
	}

	.search {
		width: 620rpx;
		margin: 20rpx auto;


	}
</style>